<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>demo</title>
  <!-- for ie9+ -->
  <script src="https://cdn.bootcss.com/fetch/2.0.3/fetch.min.js"></script>
  <script src="https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
  <script src="https://cdn.bootcss.com/axios/0.17.1/axios.min.js"></script>
  <script type="text/javascript" src="../dist/fetch2.js"></script>
<script type="text/javascript">

  Fetch2.request.use(function (req, next) {
    console.log('请求拦截', req)
    next()
  })
  Fetch2.response.use(function (res, next) {
    console.log('响应拦截', res)
    next()
  })

  Fetch2.get('http://localhost:3000/examples/api.php?key=val').then(function (res) {
    console.log(res.data)
  }).catch(function (err) {
    console.log('请求错误', err)
  })

  Fetch2.get('http://localhost:3000/examples/api.php?key=val', {
    params: {
      name: 'test',
      createdAt: 'desc'
    }
  }).then(function (res) {
    console.log(res.data)
  }).catch(function (err) {
    console.log('请求错误', err)
  })

  Fetch2.post('http://localhost:3000/examples/api.php', {
    body: {
      name: 'admin',
      pass: '123456',
      type: 1,
      info: {
        bool: true,
        arr: ['aaa', 'bbb', 'ccc']
      }
    },
    params: {
      key: 'val'
    }
  }).then(function (res) {
    console.log(res.data)
  }).catch(function (err) {
    console.log('请求错误', err)
  })

  var formData = new FormData()
  formData.append('file', new Blob(['xxxx']))
  formData.append('key', 'val')
  Fetch2.post('http://localhost:3000/examples/api.php', {
    body: formData
  })
  axios.post('http://localhost:3000/examples/api.php', formData, {
    headers: {
      'Content-Type': 'multipart/form-data; charset=UTF-8'
    }
  })
</script>
</head>
<body>
  
</body>
</html>